package com.ymatou.iapi.trading.operate.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.BargainGroupService;
import com.ymatou.iapi.trading.operate.parameter.Order;
import com.ymatou.iapi.trading.operate.parameter.OrderInfoPo;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderService;
import com.ymatou.iapi.trading.operate.parameter.req.ApplySalesRefundRequestBean;
import com.ymatou.iapi.trading.operate.parameter.req.BatchValidateRefundReq;
import com.ymatou.iapi.trading.operate.parameter.vo.ValidateRefundVo;
import com.ymatou.iapi.trading.operate.service.ApplySalesRefundRequestCall;
import com.ymatou.iapi.trading.operate.service.BatchValidateRefundCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.common.enums.CancelOrderTypeEnum;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.constant.ECode;

/**
 * 退货退款申请效验接口 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_BatchValidateRefund {
	private static BatchValidateRefundReq applyvalidationBean;
	private static BatchValidateRefundCall applyvalidationCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("批量退货退款申请校验接口");
	}

	@Before
	public void caseUp() {
		applyvalidationBean = new BatchValidateRefundReq();
		applyvalidationCall = new BatchValidateRefundCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(applyvalidationCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_001() {
		Logger.start(true, "用户下单后申请效验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			List<ValidateRefundVo> refundList = Arrays
					.asList(new ValidateRefundVo(placeOrderResp.getOrderList()
							.get(0).getOrderInfoList().get(0).getCatalogId(),
							1, BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();

			Logger.verifyEquals(ECode.FAILED201,
					applyvalidationCall.getString("code"), "验证返回码");

			Logger.verifyEquals("114", applyvalidationCall.getString("bcode"),
					"验证返回码");

			Logger.verifyEquals("申请退款金额不能大于实际可退款金额",
					applyvalidationCall.getString("msg"), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_002() {
		Logger.start(true, "用户支付后接单前效验成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			List<OrderInfoPo> orderInfos = placeOrderResp.getOrderList().get(0)
					.getOrderInfoList();

			List<ValidateRefundVo> refundList = Arrays.asList(
					new ValidateRefundVo(orderInfos.get(0).getCatalogId(), 1,
							BigDecimal.ONE), new ValidateRefundVo(orderInfos
							.get(1).getCatalogId(), 1, BigDecimal.ONE),
					new ValidateRefundVo(orderInfos.get(2).getCatalogId(), 1,
							BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();
			Logger.verifyEquals(ECode.SUCCESS,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals("0", applyvalidationCall.getString("bcode"),
					"验证返回码");

			Map<String, Object> map = applyvalidationCall.getRespMap();

			for (ValidateRefundVo refund : refundList) {

				String catalogId = refund.getCatalogId();

				Logger.comment(String.format("catalogId:%s 退款单校验结果", catalogId));

				Map<String, Object> temp = (Map<String, Object>) map
						.get(catalogId);

				Logger.verifyEquals(false,
						(Boolean) temp.get("isValidationPass"),
						"验证isValidationPass");

				Logger.verifyEquals(true, (Boolean) temp.get("success"),
						"验证success");

			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_003() {
		Logger.start(true, "商家接单前取消订单,效验成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int userId = placeOrderResp.getUserId();

			// 取消订单
			new OrderCallService().cancelOrder(orderId, userId);

			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			List<ValidateRefundVo> refundList = Arrays
					.asList(new ValidateRefundVo(placeOrderResp.getOrderList()
							.get(0).getOrderInfoList().get(0).getCatalogId(),
							1, BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();

			Logger.verifyEquals(ECode.FAILED201,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals(
					"订单已取消，不能退货退款：" + applyvalidationBean.getOrderId(),
					applyvalidationCall.getString("msg"), "验证返回码");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_004() {
		Logger.start(true, "商家接单后,退货退款校验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderCallService = new OrderCallService();
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 付款
			orderCallService.orderPayRequest(userId, totalPrice, tradingId);
			// 接单
			orderCallService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			List<ValidateRefundVo> refundList = Arrays
					.asList(new ValidateRefundVo(placeOrderResp.getOrderList()
							.get(0).getOrderInfoList().get(0).getCatalogId(),
							1, BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);

			applyvalidationCall.callService();

			Logger.verifyEquals(ECode.SUCCESS,
					applyvalidationCall.getString("code"), "验证返回码");

			Map<String, Object> map = applyvalidationCall.getRespMap();

			for (ValidateRefundVo refund : refundList) {

				String catalogId = refund.getCatalogId();

				Logger.comment(String.format("catalogId:%s 退款单校验结果", catalogId));

				Map<String, Object> temp = (Map<String, Object>) map
						.get(catalogId);

				Logger.verifyEquals(true, (Boolean) temp.get("success"),
						"验证success");

				Logger.verifyEquals(true,
						(Boolean) temp.get("isValidationPass"),
						"验证isValidationPass");

				Logger.verifyEquals(new Double(0),
						(Double) temp.get("refundFreight"), "验证refundFreight");

			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_005() {
		Logger.start(true, "商家接单后取消订单,效验成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			// 接单
			new OrderCallService().acceptOrder(orderId, sellerId);
			// 取消订单
			new OrderCallService().cancelOrder(orderId, userId,
					CancelOrderTypeEnum.CustomerCancelOrder);
			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			List<ValidateRefundVo> refundList = Arrays
					.asList(new ValidateRefundVo(placeOrderResp.getOrderList()
							.get(0).getOrderInfoList().get(0).getCatalogId(),
							1, BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();

			Logger.verifyEquals(ECode.FAILED201,
					applyvalidationCall.getString("code"), "验证返回码");

			Logger.verifyEquals("102", applyvalidationCall.getString("bcode"),
					"验证bcode");

			Logger.verifyEquals(String.format("订单已取消，不能退货退款：%s", orderId),
					applyvalidationCall.getString("msg"), "验证msg");

			Logger.verifyEquals(false, applyvalidationCall.getData()
					.getBoolean("success"), "验证success");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_BatchValidateRefund_006() {
		Logger.start(false, "订单退货退款中,申请校验的金额小于等于可退款金额");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			// 接单
			new OrderCallService().acceptOrder(orderId, sellerId);
			// 退货退款中

			ApplySalesRefundRequestBean applysalesrefundrequestBean = new OrderCallService()
					.applySalesRefundRequestInJavaBean(orderId);

			applysalesrefundrequestBean.getSalesRefundInfoList().get(0)
					.setRefundAmount(BigDecimal.TEN);
			ApplySalesRefundRequestCall applysalesrefundrequestCall = new ApplySalesRefundRequestCall();
			applysalesrefundrequestCall.setData(applysalesrefundrequestBean);
			applysalesrefundrequestCall.callService();

			List<OrderInfoPo> orderInfos = placeOrderResp.getOrderList().get(0)
					.getOrderInfoList();

			applyvalidationBean.setOrderId(orderId);

			List<ValidateRefundVo> refundList = Arrays.asList(
					new ValidateRefundVo(orderInfos.get(0).getCatalogId(), 1,
							BigDecimal.ONE), new ValidateRefundVo(orderInfos
							.get(1).getCatalogId(), 1, BigDecimal.ONE),
					new ValidateRefundVo(orderInfos.get(2).getCatalogId(), 1,
							BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();

			Logger.verifyEquals(ECode.SUCCESS,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals("0", applyvalidationCall.getString("bcode"),
					"验证返回码");
			Map<String, Object> map = applyvalidationCall.getRespMap();

			for (ValidateRefundVo refund : refundList) {

				String catalogId = refund.getCatalogId();

				Logger.comment(String.format("catalogId:%s 退款单校验结果", catalogId));

				Map<String, Object> temp = (Map<String, Object>) map
						.get(catalogId);

				Logger.verifyEquals(true, (Boolean) temp.get("success"),
						"验证success");

				Logger.verifyEquals(true,
						(Boolean) temp.get("isValidationPass"),
						"验证isValidationPass");

				Logger.verifyEquals(new Double(0),
						(Double) temp.get("refundFreight"), "验证refundFreight");

			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_BatchValidateRefund_007() {
		Logger.start(false, "订单退货退款中,有商品申请校验的金额大于最大可退款金额");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			// 退货退款中
			// 申请退款
			ApplySalesRefundRequestBean applysalesrefundrequestBean = new OrderCallService()
					.applySalesRefundRequestInJavaBean(orderId);

			ApplySalesRefundRequestCall applysalesrefundrequestCall = new ApplySalesRefundRequestCall();
			applysalesrefundrequestCall.setData(applysalesrefundrequestBean);
			applysalesrefundrequestCall.callService();

			applyvalidationBean.setOrderId(orderId);

			List<OrderInfoPo> orderInfos = placeOrderResp.getOrderList().get(0)
					.getOrderInfoList();

			List<ValidateRefundVo> refundList = Arrays.asList(
					new ValidateRefundVo(orderInfos.get(0).getCatalogId(), 1,
							BigDecimal.ONE), new ValidateRefundVo(orderInfos
							.get(1).getCatalogId(), 1, BigDecimal.ONE),
					new ValidateRefundVo(orderInfos.get(2).getCatalogId(), 1,
							BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);

			applyvalidationCall.callService();

			Logger.verifyEquals(ECode.SUCCESS,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals("0", applyvalidationCall.getString("bcode"),
					"验证返回码");

			Map<String, Object> map = applyvalidationCall.getRespMap();

			for (ValidateRefundVo refund : refundList) {

				String catalogId = refund.getCatalogId();

				Logger.comment(String.format("catalogId:%s 退款单校验结果", catalogId));

				Map<String, Object> temp = (Map<String, Object>) map
						.get(catalogId);

				Logger.verifyEquals(true, (Boolean) temp.get("success"),
						"验证success");

				Logger.verifyEquals(false,
						(Boolean) temp.get("isValidationPass"),
						"验证isValidationPass");

				Logger.verifyEquals(new Double(0),
						(Double) temp.get("refundFreight"), "验证refundFreight");

			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_008() {
		Logger.start(true, "用户收货之后申请校验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			// 接单
			new OrderCallService().acceptOrder(orderId, sellerId);
			// 商家发货
			new OrderCallService().dispatched(orderId, sellerId);
			// 确认收货
			new OrderCallService().confirmReceive(userId, orderId);
			Logger.comment("前置数据准备结束");
			applyvalidationBean.setOrderId(orderId);

			List<OrderInfoPo> orderInfos = placeOrderResp.getOrderList().get(0)
					.getOrderInfoList();

			List<ValidateRefundVo> refundList = Arrays.asList(
					new ValidateRefundVo(orderInfos.get(0).getCatalogId(), 1,
							BigDecimal.ONE), new ValidateRefundVo(orderInfos
							.get(1).getCatalogId(), 1, BigDecimal.ONE),
					new ValidateRefundVo(orderInfos.get(2).getCatalogId(), 1,
							BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();
			Logger.verifyEquals(ECode.SUCCESS,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals("0", applyvalidationCall.getString("bcode"),
					"验证返回码");

			Map<String, Object> map = applyvalidationCall.getRespMap();

			for (ValidateRefundVo refund : refundList) {

				String catalogId = refund.getCatalogId();

				Logger.comment(String.format("catalogId:%s 退款单校验结果", catalogId));

				Map<String, Object> temp = (Map<String, Object>) map
						.get(catalogId);

				Logger.verifyEquals(true, (Boolean) temp.get("success"),
						"验证success");

				Logger.verifyEquals(true,
						(Boolean) temp.get("isValidationPass"),
						"验证isValidationPass");

				Logger.verifyEquals(new Double(0),
						(Double) temp.get("refundFreight"), "验证refundFreight");

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_BatchValidateRefund_009() {
		Logger.start(false, "订单号不存在申请效验");
		try {

			applyvalidationBean.setOrderId(11111);

			List<ValidateRefundVo> refundList = Arrays
					.asList(new ValidateRefundVo("sdfsdf", 1, BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);
			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();

			Logger.verifyEquals(ECode.FAILED201,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals("订单不存在:" + applyvalidationBean.getOrderId(),
					applyvalidationCall.getString("msg"), "验证错误提示");
			Logger.verifyEquals(false, applyvalidationCall.getData()
					.getBoolean("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_BatchValidateRefund_010() {
		Logger.start(false, "订单号为null申请效验");
		try {
			// applyvalidationBean.setOrderId(111111);

			List<ValidateRefundVo> refundList = Arrays
					.asList(new ValidateRefundVo("sdfsdf", 1, BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();

			Logger.verifyEquals(ECode.FAILED400,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals("orderId:订单号不能为空",
					applyvalidationCall.getString("msg"), "验证错误提示");

			Logger.verifyEquals(false, applyvalidationCall.getData()
					.getBoolean("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_014() {
		Logger.start(true, "商家发货后,退货退款校验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderCallService = new OrderCallService();

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 付款
			orderCallService.orderPayRequest(userId, totalPrice, tradingId);
			// 接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 发货
			orderCallService.dispatched(orderId, sellerId);
			Logger.comment("前置数据准备结束");
			applyvalidationBean.setOrderId(orderId);

			List<OrderInfoPo> orderInfos = placeOrderResp.getOrderList().get(0)
					.getOrderInfoList();

			List<ValidateRefundVo> refundList = Arrays
					.asList(new ValidateRefundVo(orderInfos.get(0)
							.getCatalogId(), 1, BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);
			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();
			Logger.verifyEquals(ECode.SUCCESS,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals("0", applyvalidationCall.getString("bcode"),
					"验证返回码");

			Map<String, Object> map = applyvalidationCall.getRespMap();

			for (ValidateRefundVo refund : refundList) {

				String catalogId = refund.getCatalogId();

				Logger.comment(String.format("catalogId:%s 退款单校验结果", catalogId));

				Map<String, Object> temp = (Map<String, Object>) map
						.get(catalogId);

				Logger.verifyEquals(true, (Boolean) temp.get("success"),
						"验证success");

				Logger.verifyEquals(true,
						(Boolean) temp.get("isValidationPass"),
						"验证isValidationPass");

				Logger.verifyEquals(new Double(0),
						(Double) temp.get("refundFreight"), "验证refundFreight");

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_015() {
		Logger.start(true, "确认收货15天后,退货退款校验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderCallService = new OrderCallService();
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 付款
			orderCallService.orderPayRequest(userId, totalPrice, tradingId);
			// 接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 发货
			orderCallService.dispatched(orderId, sellerId);
			// 确认收货
			orderCallService.confirmReceive(userId, orderId);
			new DefaultWapper().updateOrderConfirmedTimeByOrderId(orderId);

			Logger.comment("前置数据准备结束");
			applyvalidationBean.setOrderId(orderId);

			List<OrderInfoPo> orderInfos = placeOrderResp.getOrderList().get(0)
					.getOrderInfoList();

			List<ValidateRefundVo> refundList = Arrays
					.asList(new ValidateRefundVo(orderInfos.get(0)
							.getCatalogId(), 1, BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);
			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();
			Logger.verifyEquals(ECode.SUCCESS,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals("0", applyvalidationCall.getString("bcode"),
					"验证返回码");

			Map<String, Object> map = applyvalidationCall.getRespMap();

			for (ValidateRefundVo refund : refundList) {

				String catalogId = refund.getCatalogId();

				Logger.comment(String.format("catalogId:%s 退款单校验结果", catalogId));

				Map<String, Object> temp = (Map<String, Object>) map
						.get(catalogId);

				Logger.verifyEquals(true, (Boolean) temp.get("success"),
						"验证success");

				Logger.verifyEquals(false,
						(Boolean) temp.get("isValidationPass"),
						"验证isValidationPass");

				Logger.verifyEquals(new Double(0),
						(Double) temp.get("refundFreight"), "验证refundFreight");

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_017() {
		Logger.start(true, "商品申请退款金额大于(商品可退金额+订单总运费)");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderCallService = new OrderCallService();

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Order order = placeOrderResp.getOrderList().get(0);

			int sellerId = order.getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId = order.getOrderId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();

			// 付款
			orderCallService.orderPayRequest(userId, totalPrice, tradingId);

			// 接单
			orderCallService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			List<OrderInfoPo> orderInfos = placeOrderResp.getOrderList().get(0)
					.getOrderInfoList();

			List<ValidateRefundVo> refundList = new ArrayList<ValidateRefundVo>();

			for (int i = 0; i < 1; i++) {

				OrderInfoPo po = orderInfos.get(i);

				// 计算订单总价格 商品价格 X 数量+运费
				BigDecimal refoundAmout = po.getProductPrice()
						.multiply(new BigDecimal(po.getAmount()))
						.subtract(po.getYmtCouponAmount())
						.subtract(po.getSellerCouponAmount())
						.add(order.getFreight().add(new BigDecimal("0.01")));

				ValidateRefundVo vo = new ValidateRefundVo(po.getCatalogId(),
						po.getAmount(), refoundAmout);

				refundList.add(vo);

			}

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);

			applyvalidationCall.callService();

			Logger.verifyEquals("201", applyvalidationCall.getString("code"),
					"验证返回码");

			Logger.verifyEquals(
					String.format("OrderId:%s, 申请退运费金额不能大于实际可退运费金额", orderId),
					applyvalidationCall.getString("msg"), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_019() {
		Logger.start(true, "订单商品不是包邮,批量全款加运费退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderCallService = new OrderCallService();

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Order order = placeOrderResp.getOrderList().get(0);

			int sellerId = order.getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId = order.getOrderId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();

			// 付款
			orderCallService.orderPayRequest(userId, totalPrice, tradingId);

			// 接单
			orderCallService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			List<OrderInfoPo> orderInfos = placeOrderResp.getOrderList().get(0)
					.getOrderInfoList();

			List<ValidateRefundVo> refundList = new ArrayList<ValidateRefundVo>();

			for (int i = 0; i < orderInfos.size(); i++) {

				OrderInfoPo po = orderInfos.get(i);

				// 计算订单总价格 商品价格 X 数量+运费
				BigDecimal refoundAmout = po.getProductPrice()
						.multiply(new BigDecimal(po.getAmount()))
						.subtract(po.getYmtCouponAmount())
						.subtract(po.getSellerCouponAmount())
						.add(po.getFreight());

				ValidateRefundVo vo = new ValidateRefundVo(po.getCatalogId(),
						po.getAmount(), refoundAmout);

				refundList.add(vo);

			}

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);

			applyvalidationCall.callService();

			Logger.verifyEquals("200", applyvalidationCall.getString("code"),
					"验证返回码");
			Logger.verifyEquals("null", applyvalidationCall.getString("msg"),
					"验证msg");

			Logger.verifyEquals(ECode.SUCCESS,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals("0", applyvalidationCall.getString("bcode"),
					"验证返回码");

			Map<String, Object> map = applyvalidationCall.getRespMap();

			for (OrderInfoPo refund : orderInfos) {

				String cataId = refund.getCatalogId();

				Logger.comment(String.format("catalogId:%s 退款单校验结果", cataId));

				Map<String, Object> temp = (Map<String, Object>) map
						.get(cataId);

				Logger.verifyEquals(true, (Boolean) temp.get("success"),
						"验证success");

				Logger.verifyEquals(true,
						(Boolean) temp.get("isValidationPass"),
						"验证isValidationPass");

				DataUtil.verifyDecimalEquals(refund.getFreight(),
						new BigDecimal((Double) temp.get("refundFreight")),
						"验证refundFreight");

			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_020() {
		Logger.start(true, "退款商品数量大于实际数量");

		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderCallService = new OrderCallService();

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Order order = placeOrderResp.getOrderList().get(0);

			int sellerId = order.getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId = order.getOrderId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();

			// 付款
			orderCallService.orderPayRequest(userId, totalPrice, tradingId);

			// 接单
			orderCallService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			List<OrderInfoPo> orderInfos = placeOrderResp.getOrderList().get(0)
					.getOrderInfoList();

			List<ValidateRefundVo> refundList = new ArrayList<ValidateRefundVo>();

			for (int i = 0; i < orderInfos.size(); i++) {

				OrderInfoPo po = orderInfos.get(i);

				// 计算订单总价格 商品价格 X 数量+运费
				BigDecimal refoundAmout = po.getProductPrice()
						.multiply(new BigDecimal(po.getAmount()))
						.subtract(po.getYmtCouponAmount())
						.subtract(po.getSellerCouponAmount())
						.add(po.getFreight());

				ValidateRefundVo vo = new ValidateRefundVo(po.getCatalogId(),
						po.getAmount() + 1, refoundAmout);

				refundList.add(vo);

			}

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);

			applyvalidationCall.callService();

			Logger.verifyEquals("201", applyvalidationCall.getString("code"),
					"验证返回码code");

			Logger.verifyEquals("114", applyvalidationCall.getString("bcode"),
					"验证返回码bcode");

			Logger.verifyEquals(true, applyvalidationCall.getString("msg")
					.contains("申请退商品数量不能大于实际商品数量"), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_026() {
		Logger.start(true, "订单锁定后申请效验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			new OrderCallService().markOrderLock(orderId, 1);

			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			List<OrderInfoPo> orderInfos = placeOrderResp.getOrderList().get(0)
					.getOrderInfoList();

			List<ValidateRefundVo> refundList = Arrays
					.asList(new ValidateRefundVo(orderInfos.get(0)
							.getCatalogId(), 1, BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();

			Logger.verifyEquals(ECode.FAILED201,
					applyvalidationCall.getString("code"), "验证返回码");

			Logger.verifyEquals("该订单已被洋码头客服锁定，暂时无法对该订单进行后续操作",
					applyvalidationCall.getString("msg"), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_027() {
		Logger.start(true, "虚拟商品不能发起退货退款");

		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderCallService = new OrderCallService();

			PlaceOrderResp placeOrderResp = BargainGroupService
					.placeVirtualProduct();

			Order order = placeOrderResp.getOrderList().get(0);

			int sellerId = order.getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId = order.getOrderId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();

			//第一个订单下的第一个商品
			OrderInfoPo orderInfoPo = order.getOrderInfoList().get(0);

			String catalogId = orderInfoPo.getCatalogId();

			String productId = orderInfoPo.getProductId();

			int productNum = orderInfoPo.getAmount();

			BigDecimal productFreight = orderInfoPo.getFreight();

			BigDecimal refundProductFreight = productFreight
					.subtract(new BigDecimal(2));

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			// 付款
			orderCallService.orderPayRequest(userId, totalPrice, tradingId);

			// 接单
			orderCallService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			List<OrderInfoPo> orderInfos = placeOrderResp.getOrderList().get(0)
					.getOrderInfoList();

			List<ValidateRefundVo> refundList = Arrays
					.asList(new ValidateRefundVo(orderInfos.get(0)
							.getCatalogId(), 1, BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);

			applyvalidationCall.callService();

			Logger.verifyEquals("201", applyvalidationCall.getString("code"),
					"验证返回码");

			Logger.verifyEquals("102", applyvalidationCall.getString("bcode"),
					"验证bcode");
			Logger.verifyEquals("虚拟商品不能发起退货退款",
					applyvalidationCall.getString("msg"), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_028() {
		Logger.start(true, "批量退款校验,其中有商品退款金额大于实际可退金额(商品+商品运费)");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			// 接单
			new OrderCallService().acceptOrder(orderId, sellerId);
			// 商家发货
			new OrderCallService().dispatched(orderId, sellerId);
			// 确认收货
			new OrderCallService().confirmReceive(userId, orderId);
			Logger.comment("前置数据准备结束");
			applyvalidationBean.setOrderId(orderId);

			List<OrderInfoPo> orderInfos = placeOrderResp.getOrderList().get(0)
					.getOrderInfoList();

			List<ValidateRefundVo> refundList = new ArrayList<ValidateRefundVo>();

			for (int i = 0; i < orderInfos.size(); i++) {

				OrderInfoPo po = orderInfos.get(i);

				BigDecimal refundProFreight = po.getFreight();

				if (i == orderInfos.size() - 1) {

					refundProFreight = refundProFreight.add(new BigDecimal(
							"0.01"));

				}

				// 计算订单总价格 商品价格 X 数量+运费
				BigDecimal refoundAmout = po.getProductPrice()
						.multiply(new BigDecimal(po.getAmount()))
						.subtract(po.getYmtCouponAmount())
						.subtract(po.getSellerCouponAmount())
						.add(refundProFreight);

				ValidateRefundVo vo = new ValidateRefundVo(po.getCatalogId(),
						po.getAmount(), refoundAmout);

				refundList.add(vo);

			}

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();
			Logger.verifyEquals("201", applyvalidationCall.getString("code"),
					"验证返回码");
			Logger.verifyEquals("114", applyvalidationCall.getString("bcode"),
					"验证返回码");

			Logger.verifyEquals("201", applyvalidationCall.getString("code"),
					"验证返回码");

			Logger.verifyEquals("申请退款金额不能大于实际可退款金额",
					applyvalidationCall.getString("msg"), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_029() {
		Logger.start(true, "批量退款校验,其中有商品退款商品数量大于最大可退数量");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			// 接单
			new OrderCallService().acceptOrder(orderId, sellerId);
			// 商家发货
			new OrderCallService().dispatched(orderId, sellerId);
			// 确认收货
			new OrderCallService().confirmReceive(userId, orderId);
			Logger.comment("前置数据准备结束");
			applyvalidationBean.setOrderId(orderId);

			List<OrderInfoPo> orderInfos = placeOrderResp.getOrderList().get(0)
					.getOrderInfoList();

			List<ValidateRefundVo> refundList = new ArrayList<ValidateRefundVo>();

			for (int i = 0; i < orderInfos.size(); i++) {

				OrderInfoPo po = orderInfos.get(i);

				BigDecimal refundProFreight = po.getFreight();
				int refundNum = po.getAmount();

				if (i == orderInfos.size() - 1) {
					refundNum = refundNum + 1;
				}

				// 计算订单总价格 商品价格 X 数量+运费
				BigDecimal refoundAmout = po.getProductPrice()
						.multiply(new BigDecimal(po.getAmount()))
						.subtract(po.getYmtCouponAmount())
						.subtract(po.getSellerCouponAmount())
						.add(refundProFreight);

				ValidateRefundVo vo = new ValidateRefundVo(po.getCatalogId(),
						refundNum, refoundAmout);

				refundList.add(vo);

			}

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();

			Logger.verifyEquals("114", applyvalidationCall.getString("bcode"),
					"验证返回码");

			Logger.verifyEquals("201", applyvalidationCall.getString("code"),
					"验证返回码");

			Logger.verifyEquals(true, applyvalidationCall.getString("msg")
					.contains("申请退商品数量不能大于实际商品数量"), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
